﻿using CsvHelper;
using SoapStudio.Common;
using SoapStudio.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace SoapStudio.Worker
{
    public class OilWorker
    {
        public string? OilFilePath { get; set; }

        public OilWorker()
        {
            OilFilePath = AppContext.BaseDirectory + @"Assets\Datas\OilData2.csv";
        }

        public ObservableCollection<OilModel>? GetAllOils()
        {
            try
            {
                var oilData = CSVHelper.ReadCSV<OilModel>(OilFilePath!);
                if (oilData != null && oilData.Count > 0)
                {
                    return new ObservableCollection<OilModel>(oilData);
                }
                else
                {
                    MessageBox.Show("没有找到油脂数据，请检查文件路径或文件内容。");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return null;
        }
    }
}
